<?php @session_start(); ?>
<?php
if($_SERVER['REMOTE_ADDR'] == '127.0.0.1')
{
	$base_url = "http://www.iqtest.com/";
}
else 
{
	$base_url = "http://iqtest.msitrsu.com/";
}
?> 
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>IQ TEST</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="<?php echo $base_url;?>css/bootstrap.css" media="screen">
    <link rel="stylesheet" href="<?php echo $base_url;?>css/bootswatch.min.css">
	<link rel="stylesheet" href="<?php echo $base_url;?>css/form_validation.css">
    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="<?php echo $base_url;?>js/html5shiv.js"></script>
      <script src="<?php echo $base_url;?>js/respond.min.js"></script>
    <![endif]-->
	<script src="<?php echo $base_url;?>js/jquery-1.10.2.min.js"></script>
	<script src="<?php echo $base_url;?>js/jquery.validate.min.js" type="text/javascript"></script>
	<script src="<?php echo $base_url;?>js/bootstrap.min.js"></script>
    <script src="<?php echo $base_url;?>js/bootswatch.js"></script>
	<script type="text/javascript">
	$(document).ready(function () {
	$("#infoForm").validate({
	   rules: {
			name: "required"
		},
       submitHandler: function(form) {
    	   $.ajax({
 	          type: "POST",
 	          url: "member_register.php",
 	          data: $('#infoForm').serialize(),
 	       success: function(result)
 	       {
 	    	  if(result == 1){
					window.location.href = '<?php echo $base_url;?>excercise/lists.php';
				}else{
					alert('พบข้อผิดพลาดไม่สามารถดำเนินการต่อได้');
				}
 	       }
 	     });
       }
	})
	});
	</script>
  </head>
  <body>
<?php include ("../menu.php"); ?>
    <div class="container">  
      <!-- Forms
      ================================================== -->
      <div>
        <div class="row">
          <div class="col-lg-12">
            <div class="page-header">
              <?php if(isset($_POST['stucode'])){?><h2 id="forms">กรุณาตรวจสอบชื่อ</h2><?php } ?>
            </div>
          </div>
        </div>
		<div class="row">
		<div class="well bs-component">
<?php  
		if(isset($_POST['stucode']) || isset($_SESSION['student_code']))
		{
			include "../dbconnect.php";
			$student_code = (isset($_POST['stucode']))?$_POST['stucode']:$_SESSION['student_code'];

			$sql = "SELECT * FROM student WHERE student_code=".$student_code;
			$result = mysql_query($sql, $link);
			mysql_query("SET NAMES UTF8");  
			$numrows = mysql_num_rows($result);
			if($numrows > 0)
			{			
				while ($arr = mysql_fetch_array($result))
				{
					$name = $arr['name'];
?>				
              <form class="form-horizontal" id="infoForm" method="post" action="">
                <fieldset>
                  <legend>&nbsp;</legend>
				  <div class="form-group">
                    <label for="" class="col-lg-2 control-label">ชื่อ</label>
                    <div class="col-lg-10">
                      <input type="text" class="form-control" id="name" placeholder="ชื่อ..." name="name" value="<?php echo $name;?>">
                    </div>
                  </div>
                  <div class="form-group">
                    <div class="col-lg-10 col-lg-offset-2">
						<button type="submit" class="btn btn-primary">ยืนยัน</button>
						<button class="btn btn-default">ยกเลิก</button>
                    </div>
                  </div>
                </fieldset>
              </form>

<?php				}
			}
			else
			{
				echo 'ไม่พบข้อมูล';
			}			
		}
		else
		{
			echo 'ไม่พบข้อมูล';
		}
?>
  </div>
        </div>
      </div>
      <footer>
        <div class="row">
          <div class="col-lg-12">
            <ul class="list-unstyled">
              <li class="pull-right"><a href="#top">Back to top</a></li>
            </ul>
          </div>
        </div>
      </footer>
    </div>
  </body>
</html>
